package com.nervenets.shopping.config;

import com.nervenets.general.redis.RedisSyncLocker;
import com.nervenets.general.service.RedisService;
import com.nervenets.shopping.event.DataOfUserEventListener;
import com.nervenets.shopping.event.GroupBuyOrderSuccessEventListener;
import com.nervenets.shopping.service.*;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;

import javax.annotation.Resource;

@EnableAsync
@Configuration
@AllArgsConstructor
@EnableAspectJAutoProxy
@ConditionalOnWebApplication
public class EventListenerConfiguration {
    @Resource
    private final RedisService redisService;
    @Resource
    private final DataOfUserService dataOfUserService;
    @Resource
    private final DataOfDayStateService dataOfDayStateService;
    @Resource
    private final UserService userService;
    @Resource
    private final WealthFlowService wealthFlowService;
    @Resource
    private final RechargeOrderService rechargeOrderService;
    @Resource
    private final GroupBuyOrderUserService groupBuyOrderUserService;
    @Resource
    private GroupBuyOrderService groupBuyOrderService;
    @Resource
    private RedisSyncLocker redisSyncLocker;

    @Bean
    public DataOfUserEventListener dataOfUserEventListener() {
        return new DataOfUserEventListener(
                dataOfUserService,
                userService,
                rechargeOrderService,
                groupBuyOrderUserService
        );
    }

    @Bean
    public GroupBuyOrderSuccessEventListener groupBuyOrderSuccessEventListener() {
        return new GroupBuyOrderSuccessEventListener(groupBuyOrderService, redisSyncLocker);
    }
}
